<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>箱型管理</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body>
<div id="payment"></div>
</body>
<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
	var store = Ext.create('Ext.data.Store', {
		fields: ["ID","SUPPLIER","ACCOUNT_BANK","ACCOUNT_BANK_NUMBER","CURRENCY"],
		pageSize: 30,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>paymentUnit/findPaymentUnitInfo',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'root',  //数据
				totalProperty: 'total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
		autoLoad: true
	});
	var bizhong = Ext.create('Ext.data.Store', {
		fields: ['id', 'name'],
		data : [
			{"id":"", "name":"请选择"},
			{"id":"1", "name":"RMB"},
			{"id":"0", "name":"USD"}
		]
	});
	  var c2 = Ext.create('Ext.container.Container', {
			layout: 'column',
// 			defaults: { labelAlign: 'left', labelWidth: 80 },
			items: [
				{id:"startDate5",xtype: 'textfield',labelWidth: 90, name: 'startDate5', columnWidth:  1/5,padding: '5px',hidden:true},
				{id:"startDate1",xtype: 'textfield',labelWidth: 90, name: 'startDate1', columnWidth:  1/5,padding: '5px', fieldLabel: '供应商发票抬头'},
				{id:"startDate2",xtype: 'textfield',labelWidth: 50, name: 'startDate2',columnWidth: 1/5,padding: '5px',fieldLabel: '开户行'},
				{id:"startDate3",xtype: 'textfield', labelWidth: 70,name: 'startDate3',columnWidth: 1/5,padding: '5px',fieldLabel: '开户行账号'},
				{id:"startDate4",xtype: 'combo',labelWidth: 40,store:bizhong, name: 'startDate4',displayField:'name',columnWidth: 1/5,padding: '5px',fieldLabel: '币种'},
			]
		});
	  var bs2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 2/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/table_refresh.png', text: "查询",handler: function(){
			      		 var SUPPLIER = Ext.getCmp('startDate1').getValue();
				      		var ACCOUNT_BANK = Ext.getCmp('startDate2').getValue();
				      		var ACCOUNT_BANK_NUMBER = Ext.getCmp('startDate3').getValue();
				      		var CURRENCY = Ext.getCmp('startDate4').getValue();
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		SUPPLIER : encodeURI(SUPPLIER), ACCOUNT_BANK:encodeURI(ACCOUNT_BANK),ACCOUNT_BANK_NUMBER:encodeURI(ACCOUNT_BANK_NUMBER),CURRENCY:encodeURI(CURRENCY)
				            };  
					//这里apply一下实现新的proxy  
				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
					//对store重新载入  
				        store.load();  


							
				      	 } },
				      	{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "添加",handler: function(){
				      		 var SUPPLIER = Ext.getCmp('startDate1').getValue();
					      		var ACCOUNT_BANK = Ext.getCmp('startDate2').getValue();
					      		var ACCOUNT_BANK_NUMBER = Ext.getCmp('startDate3').getValue();
					      		var CURRENCY = Ext.getCmp('startDate4').getValue();
					      		Ext.Ajax.request({
					      			 url: '<%=basePath%>paymentUnit/saveOrUpdatePaymentUnitInfo',
					      			 params:{SUPPLIER : SUPPLIER, ACCOUNT_BANK:ACCOUNT_BANK,ACCOUNT_BANK_NUMBER:ACCOUNT_BANK_NUMBER,CURRENCY:CURRENCY},
					      			 method: 'POST',
					        			success: function () {
											Ext.getCmp("startDate1").setValue(null); 
											Ext.getCmp("startDate2").setValue(null); 
											Ext.getCmp("startDate3").setValue(null); 
											Ext.getCmp("startDate4").setValue(null);
											store.load();
					        			}
					      		});
				      	},
				      	},
				      	{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "保存修改信息",handler: function(){
				      		 var SUPPLIER = Ext.getCmp('startDate1').getValue();
					      		var ACCOUNT_BANK = Ext.getCmp('startDate2').getValue();
					      		var ACCOUNT_BANK_NUMBER = Ext.getCmp('startDate3').getValue();
					      		var CURRENCY = Ext.getCmp('startDate4').getValue();
					      		var ID = Ext.getCmp('startDate5').getValue();
					      		Ext.Ajax.request({
					      			 url: '<%=basePath%>paymentUnit/saveOrUpdatePaymentUnitInfo',
					      			 params:{ID:ID,SUPPLIER : SUPPLIER, ACCOUNT_BANK:ACCOUNT_BANK,ACCOUNT_BANK_NUMBER:ACCOUNT_BANK_NUMBER,CURRENCY:CURRENCY},
					      			 method: 'POST',
					        			success: function () {
											Ext.getCmp("startDate1").setValue(null); 
											Ext.getCmp("startDate2").setValue(null); 
											Ext.getCmp("startDate3").setValue(null); 
											Ext.getCmp("startDate4").setValue(null);
											store.load();
					        			}
					      		});
				      	}
				      	}

				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	
		var invoice_unit_cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 2});
	var grid = Ext.create('Ext.grid.Panel', {
// 		renderTo:'payment',
		store: store,
		id:'grid',
		forceFit: true,
		height: 550,
		title:'付款单位',
		stripeRows:true,
		columnLines: true,
		plugins:[invoice_unit_cellEditing],
		selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
		columns: [
			{text: 'ID', dataIndex: 'ID',hidden:true},
			{text: '供应商发票抬头', dataIndex: 'SUPPLIER'},
			{text: '开户行', dataIndex: 'ACCOUNT_BANK'},
			{text: '开户行账号', dataIndex: 'ACCOUNT_BANK_NUMBER'},
			{text: '币种', dataIndex: 'CURRENCY', align: 'left'},
		],
		bbar: [{
			xtype: 'pagingtoolbar',
// 			store: store,
			displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
			emptyMsg: "没有数据",
			beforePageText: "当前页",
			afterPageText: "共{0}页",
			displayInfo: true
		}],

		tbar: [
			{text: '修改', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/cog_edit.png', handler: function (){
				 var records = grid.getSelectionModel().getSelection();
			   	 if(records.length==0){
			     			Ext.Msg.alert("提示","请选择一条记录");return;
			     		}
			     		if(records.length>1){
			     			Ext.Msg.alert("提示","只能编辑一条记录");return;
			     		}
			     		
			     		
			     		Ext.getCmp("startDate1").setValue(records[0].data.SUPPLIER); 
						Ext.getCmp("startDate2").setValue(records[0].data.ACCOUNT_BANK); 
						Ext.getCmp("startDate3").setValue(records[0].data.ACCOUNT_BANK_NUMBER); 
						Ext.getCmp("startDate4").setValue(records[0].data.CURRENCY);
						Ext.getCmp("startDate5").setValue(records[0].data.ID);
			} },
			{text: '删除', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/cross.gif', handler: function (){
				var records = grid.getSelectionModel().getSelection();
       			if(records.length==0){
       				Ext.Msg.alert("提示","请选中需要删除的实体记录");return;
       			}
       			var arr = [];
       			Ext.each(records,function(item){
       				obj = {
       						id:item.data.ID
       				};
       				arr.push(obj);
       			});
       			var array = JSON.stringify(arr);
       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
	       				
	       					Ext.Ajax.request({
	       						url:'<%=basePath%>paymentUnit/deletePaymentUnitInfo',
	       						params:{
	       							array:array
	       						},
	       						timeout:5000,
	       						success:function(response){
	       							store.load();
	       							Ext.Msg.alert("成功","删除成功!");
	       						},
	       						failure:function(response){
	       							Ext.Msg.alert("错误","请求异常!");
	       						}
	       					});
	       				
	       			});
			} },{text: '导出', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/folder_go.gif', handler: function (){
				 var records = grid.getSelectionModel().getSelection();
			   	 if(records.length==0){
			     			Ext.Msg.alert("提示","请选择一条记录导出");return;
			     		}
			     		if(records.length>1){
			     			Ext.Msg.alert("提示","只能选择一条记录导出");return;
			     		}
			     		
				document.location.href="<%=basePath%>common/export/exportExcel?exportType="+"paymentUnit"+"&ID="+records[0].data.ID;
			}
			},{text: '导入', icon: '<%=basePath%>plugins/websocketInstantMsg/ext4/shared/icons/fam/control_rewind.png', handler:
				 toImport
			
			},
			]
	});
	  var selForm = Ext.create('Ext.form.Panel', {
			title:'箱型管理',
			name: 'selForm',
			renderTo:'payment',
			width:'100%',
//			collapsed :true,
			height:'96%',
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c2,bs2,grid]
		});
	  var uploadForm = Ext.create('Ext.form.Panel', {
		    items: [
		        {
		            xtype: 'filefield',
		            fieldLabel: '文件上传',
		            name:"file",
		            labelWidth: 80,
		            msgTarget: 'side',
		            allowBlank: false,
		            emptyText: "请选择上传文件",
		            blankText:"请选择上传文件",
		            margin: '10,10,10,10',
		            anchor: '100%',
		            buttonText:'选择文件'
		        }],
		    buttonAlign:'center'

		});


		var impWin = Ext.create('Ext.window.Window', {
		    title: '支付单位',
		    modal : true,
		    items: [uploadForm],
		    closeAction: 'hide',
		    closeable: true,
		    iconCls: 'modalWin',
		    buttonAlign: 'center',
		    buttons: [
		        {text: '导入',handler: function() { impSubmit(); }},
		        {text: '关闭', handler: function() { impWin.close(); }}
		    ]
		});

		function impSubmit(){
		    uploadForm.getForm().submit({
		        url: '<%=basePath%>paymentUnit/paymentUnitInfo',
		        success: function(form, action) {
		        	Ext.Msg.alert("提示","导入成功！");
		        	store.load();  
		        	 impWin.close();
		        },
			failure: function(form, action){  
				Ext.Msg.alert("提示","导入失败！");
		    	store.load();  
		      }  
		    });
		}

		function toImport(){
		    impWin.show();
		}
	  
});

</script>
</html>